<template>
  <u-container-layout>
    <zlrt-table :p="ctx">
      <template #before>
        <zlrt-search :p="ctx"></zlrt-search>
         <div style="margin-bottom: 10px;">
          <el-button type="danger" v-hasPermit="['core:tenant:del']" icon="Delete"
            :disabled="!ctx.selected.length" @click="ctx.batchDelete()">
            批量删除
          </el-button>
          <span style="float:right">
            <el-button type="success" v-hasPermit="['core:tenant:list']" :loading="ctx.exportLoading" icon="Download"
              @click="ctx.export()">
              导出
            </el-button>
            <el-button type="primary" v-hasPermit="['core:tenant:save']" icon="Plus" @click="ctx.showEdit()">
              添加
            </el-button>
          </span>
        </div>
      </template>
      <template #disabled="scope">
          <el-switch
            v-model="scope.row.disabled"
            :active-value="false"
            :inactive-value="true"
            @change="ctx.other.statusChanged(scope.row)"
          />
      </template>
      <template #expiration="scope">
          {{ ctx.other.formatDate(scope.row.expiration) }}
      </template>
      <template #operation="scope">
        <el-button type="primary" v-hasPermit="['core:tenant:save']" link size="small" icon="Edit"
          @click="ctx.showEdit(scope.row)">
          编辑
        </el-button>
        <el-button type="danger" v-hasPermit="['core:tenant:del']" link size="small"
          icon="Delete" @click="ctx.del(scope.row.id)" >
          删除
        </el-button>
      </template>
      <template #after>
        <el-dialog v-model="ctx.editVisible" :title="ctx.editAction + ctx.title" width="600px"
          append-to-body :close-on-click-modal="false" @close="ctx.closeEdit()">
          <el-form :ref="(e) => ctx.formRef = e" :model="ctx.editData" :rules="ctx.rules"
            v-loading="ctx.editLoading" label-width="120px" class="demo-ruleForm">
            <el-form-item label="租户名称" prop="name">
              <el-input v-model="ctx.editData.name" placeholder="请输入租户名称"/>
            </el-form-item>
            <el-form-item label="到期时间" prop="expiration">
              <el-date-picker
                v-model="ctx.editData.expiration"
                type="date"
                placeholder="请选择到期时间"
              />
            </el-form-item>
            <el-form-item label="状态" prop="disabled">
              <el-select v-model="ctx.editData.disabled" placeholder="请选择状态">
                <el-option v-for="ite in disabledOptions" :key="ite.value" :label="ite.label" :value="ite.value" />
              </el-select>
            </el-form-item>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="ctx.editVisible = false">取消</el-button>
              <el-button type="primary" @click="ctx.save()">确定</el-button>
            </span>
          </template>
        </el-dialog>
      </template>
    </zlrt-table>
  </u-container-layout>
</template>

<script lang="ts" src="./tenant.ts" />

<style lang="scss" scoped>
</style>
